package com.yanqu.road.server.agent.inter;

import com.alibaba.fastjson.JSONObject;
import com.yanqu.road.entity.enums.eAgentErrorCode;
import com.yanqu.road.server.agent.AgentInterfaceMgr;
import com.yanqu.road.server.manager.activity.bulletscreen.CrossActivityBulletScreenMgr;
import com.yanqu.road.server.manager.cross.battle.dunhuangshiku.DunHuangShiKuActivity;
import com.yanqu.road.server.manager.cross.battle.dunhuangshiku.DunHuangShiKuMgr;
import com.yanqu.road.server.manager.douluodalu.CrossDouLouDaLuActivity;
import com.yanqu.road.server.manager.douluodalu.CrossDouLuoDaLuMgr;
import com.yanqu.road.server.manager.union.activitygroup.Cross2UnionActivityGroupMgr;


public class AgentCrossRename {
    public String adminQueryBulletScreen(JSONObject param){
        JSONObject resultObj = AgentInterfaceMgr.getDefaultRet();
        long userId = param.getLongValue("userId");
        long serverId = param.getLongValue("serverId");
        int activityId = param.getInteger("activityId");
        int ret = eAgentErrorCode.Success.getValue();
        resultObj.put("data", CrossActivityBulletScreenMgr.queryPlayerBulletScreen(activityId, userId, serverId));
        AgentInterfaceMgr.setCommonRet(resultObj, ret);
        return resultObj.toString();
    }

    public String adminRenameBulletScreen(JSONObject param){
        JSONObject resultObj = AgentInterfaceMgr.getDefaultRet();
        long userId = param.getLongValue("userId");
        long serverId = param.getLongValue("serverId");
        String changeContent = param.getString("changeContent");
        int activityId = param.getInteger("activityId");
        long contentId = param.getLongValue("contentId");
        int ret = eAgentErrorCode.Success.getValue();
        if(0 != CrossActivityBulletScreenMgr.changePlayerBulletScreen(activityId, userId, serverId, changeContent, contentId)){
            ret = eAgentErrorCode.ArgumentError.getValue();
        }
        AgentInterfaceMgr.setCommonRet(resultObj, ret);
        return resultObj.toString();
    }

    public String adminQueryDouLuo(JSONObject param){
        JSONObject resultObj = AgentInterfaceMgr.getDefaultRet();
        long userId = param.getLongValue("userId");
        int activityId = param.getInteger("activityId");
        int ret = eAgentErrorCode.Success.getValue();
        JSONObject dataObj = new JSONObject();
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        CrossDouLouDaLuActivity douLouDaLuActivity = CrossDouLuoDaLuMgr.getActivityOrNull(activityId, groupId);
        if(null != douLouDaLuActivity){
            dataObj = douLouDaLuActivity.adminQueryTeamData(userId);
        }
        resultObj.put("data", dataObj);
        AgentInterfaceMgr.setCommonRet(resultObj, ret);
        return resultObj.toString();
    }

    public String adminRenameDouLuo(JSONObject param){
        JSONObject resultObj = AgentInterfaceMgr.getDefaultRet();
        int teamId = param.getIntValue("teamId");
        long userId = param.getLongValue("userId");
        String changeContent = param.getString("changeContent");
        int activityId = param.getInteger("activityId");
        int ret = eAgentErrorCode.Success.getValue();
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        CrossDouLouDaLuActivity douLouDaLuActivity = CrossDouLuoDaLuMgr.getActivityOrNull(activityId, groupId);
        if(null == douLouDaLuActivity){
            ret = eAgentErrorCode.ArgumentError.getValue();
        }else {
            if(0 != douLouDaLuActivity.adminChangeTeamName(teamId, changeContent)){
                ret = eAgentErrorCode.ArgumentError.getValue();
            }
        }

        AgentInterfaceMgr.setCommonRet(resultObj, ret);
        return resultObj.toString();
    }

    public String adminQueryDunHuang(JSONObject param){
        JSONObject resultObj = AgentInterfaceMgr.getDefaultRet();
        long userId = param.getLongValue("userId");
        int activityId = param.getInteger("activityId");
        int ret = eAgentErrorCode.Success.getValue();
        JSONObject dataObj = new JSONObject();
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        DunHuangShiKuActivity dunHuangShiKuActivity = DunHuangShiKuMgr.getActivity(activityId, groupId);
        if(null != dunHuangShiKuActivity){
            dataObj = dunHuangShiKuActivity.adminQueryTeamData(userId);
        }
        resultObj.put("data", dataObj);
        AgentInterfaceMgr.setCommonRet(resultObj, ret);
        return resultObj.toString();
    }

    public String adminRenameDunHuang(JSONObject param){
        JSONObject resultObj = AgentInterfaceMgr.getDefaultRet();
        int teamId = param.getIntValue("teamId");
        long userId = param.getLongValue("userId");
        String changeContent = param.getString("changeContent");
        int activityId = param.getInteger("activityId");
        int ret = eAgentErrorCode.Success.getValue();
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        DunHuangShiKuActivity dunHuangShiKuActivity = DunHuangShiKuMgr.getActivity(activityId, groupId);
        if(null == dunHuangShiKuActivity){
            ret = eAgentErrorCode.ArgumentError.getValue();
        }else {
            if(0 != dunHuangShiKuActivity.adminChangeTeamName(teamId, changeContent)){
                ret = eAgentErrorCode.ArgumentError.getValue();
            }
        }

        AgentInterfaceMgr.setCommonRet(resultObj, ret);
        return resultObj.toString();
    }
}
